#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

// 函数用于将 IPv4 地址转换为十六进制字符串
string ipv4ToHex(const string& ip) {
    vector<int> parts;
    stringstream ss(ip);
    string part;

    // 按点号分割 IPv4 地址
    while (getline(ss, part, '.')) {
        parts.push_back(stoi(part));
    }

    // 组合四个 8 位整数为一个 32 位整数
    unsigned int ipValue = 0;
    for (int i = 0; i < 4; ++i) {
        ipValue = (ipValue << 8) | parts[i];
    }

    // 将 32 位整数转换为十六进制字符串
    stringstream hexStream;
    hexStream << hex << ipValue;
    string hexString = hexStream.str();

    // 确保十六进制字符串长度为 8 位
    while (hexString.length() < 8) {
        hexString = "0" + hexString;
    }

    return hexString;
}

int main() {
    string ip = "192.168.1.1";
    string hex = ipv4ToHex(ip);
    cout << "IPv4: " << ip << endl;
    cout << "Hex: 0x" << hex << endl;
    return 0;
}